/*
 * Panel.java  0.4.0 / Oct 26, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing;

import com.cute4j.swing.layouts.FlowLayout;
import com.cute4j.swing.layouts.LayoutManager;
import com.cute4j.swing.properties.PanelProperties;

/**
 * Panel Component.
 *
 * @cute4j.native
 *    generate="header"
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class Panel extends Container implements PanelProperties {

// Public Static Fields. -------------------------------------------------------

  /**
   * Flat panel type (the value is {@value}).
   */
  public static final int PANEL_TYPE_FLAT = 0;

  /**
   * Box panel type (the value is {@value}).
   */
  public static final int PANEL_TYPE_BOX = 1;

  /**
   * Standard panel type (the value is {@value}).
   */
  public static final int PANEL_TYPE_STANDARD = 2;

  /**
   * Classic panel type (the value is {@value}).
   */
  public static final int PANEL_TYPE_CLASSIC = 3;

  /**
   * Styled panel type (the value is {@value}).
   */
  public static final int PANEL_TYPE_STYLED = 6;

  /**
   * Plain panel border (the value is {@value}).
   */
  public static final int BORDER_STYLE_PLAIN = 16;

  /**
   * Raised panel border (the value is {@value}).
   */
  public static final int BORDER_STYLE_RAISED = 32;

  /**
   * Sunken panel border (the value is {@value}).
   */
  public static final int BORDER_STYLE_SUNKEN = 48;

// Private Fields. -------------------------------------------------------------

  private int panelType;
  private int borderStyle;
  private int borderWidth;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new Panel object.
   */
  public Panel() {
    this(new FlowLayout());
  }

  /**
   * Constructs new Panel object.
   *
   * @param layoutManager the layout manager
   */
  public Panel(LayoutManager layoutManager) {
    super(layoutManager);
    borderStyle = BORDER_STYLE_PLAIN;
    setOpaque(true);
  }

// Public Methods. -------------------------------------------------------------

  /**
   * Returns panel type.
   *
   * @return panel type
   */
  public int getPanelType() {
    return panelType;
  }

  /**
   * Sets panel type.
   *
   * @param panelType the panel type
   */
  public void setPanelType(int panelType) {
    if ((panelType != PANEL_TYPE_FLAT) && (panelType != PANEL_TYPE_BOX) &&
        (panelType != PANEL_TYPE_STANDARD) &&
        (panelType != PANEL_TYPE_CLASSIC) &&
        (panelType != PANEL_TYPE_STYLED)) {
      throw new IllegalArgumentException("Invalid panel type");
    }
    final int oldPanelType = this.panelType;
    if (oldPanelType != panelType) {
      disposedCheck();
      _setPanelType(_delegate, panelType);
      this.panelType = panelType;
      firePropertyChange(PROPERTY_PANEL_TYPE, oldPanelType, panelType);
    }
  }

  /**
   * Returns border style.
   *
   * @return border style
   */
  public int getBorderStyle() {
    return borderStyle;
  }

  /**
   * Sets border style.
   *
   * @param borderStyle the border style
   */
  public void setBorderStyle(int borderStyle) {
    if ((borderStyle != BORDER_STYLE_PLAIN) &&
        (borderStyle != BORDER_STYLE_RAISED) &&
        (borderStyle != BORDER_STYLE_SUNKEN)) {
      throw new IllegalArgumentException("Invalid border style");
    }
    final int oldBorderStyle = this.borderStyle;
    if (oldBorderStyle != borderStyle) {
      disposedCheck();
      _setBorderStyle(_delegate, borderStyle);
      this.borderStyle = borderStyle;
      firePropertyChange(PROPERTY_BORDER_STYLE, oldBorderStyle, borderStyle);
    }
  }

  /**
   * Returns border width.
   *
   * @return border width
   */
  public int getBorderWidth() {
    return borderWidth;
  }

  /**
   * Sets border width.
   *
   * @param borderWidth the width of the border
   */
  public void setBorderWidth(int borderWidth) {
    if (borderWidth < 0) {
      throw new IllegalArgumentException("Invalid border width");
    }
    final int oldBorderWidth = this.borderWidth;
    if (oldBorderWidth != borderWidth) {
      disposedCheck();
      _setBorderWidth(_delegate, borderWidth);
      this.borderWidth = borderWidth;
      firePropertyChange(PROPERTY_BORDER_WIDTH, oldBorderWidth, borderWidth);
    }
  }

// Package-Private Native Methods. ---------------------------------------------

  native long _create();

  native void _setPanelType(long delegate, int panelType);

  native void _setBorderStyle(long delegate, int borderStyle);

  native void _setBorderWidth(long delegate, int borderWidth);

}
